Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark theme for ConsoleUI #3226

Merged
merged 1 commit into from
Jan 23, 2021

Conversation

HebaruSan
Copy link
Member

Motivation

Currently ConsoleUI only supports one visual style, based on TuboVision.

image

Some users may prefer a less bright display.

Changes

Now ConsoleUI supports a --theme parameter accepting options default (the default) and dark. If you choose dark, a monochrome green-on-black style is used:

image
image

To achieve this, Toolkit.ConsoleTheme is changed from a singleton to a parameter that is passed to any spot that needs to draw things. A ConsoleTheme.Themes dictionary holds the defined themes, and new logic in ConsoleCKAN looks up the theme based on the --theme parameter and passes it to the application code.

@HebaruSan HebaruSan added Enhancement New features or functionality Pull request ConsoleUI Issues affecting the interactive console UI labels Dec 5, 2020
@HebaruSan HebaruSan requested a review from DasSkelett December 5, 2020 23:11
@techman83
Copy link
Member

Ok this is really cool!

@HebaruSan HebaruSan changed the title Support dynamic themes for ConsoleUI Dark theme for ConsoleUI Dec 29, 2020
@HebaruSan HebaruSan force-pushed the feature/consoleui-themes branch from 0c38bc0 to b397f70 Compare January 10, 2021 20:44
@DasSkelett
Copy link
Member

Haha, took me some tries to select a terminal theme that works

My default theme, not very dark:
bright-dark-theme

Second try:
invisible-dark-theme

Third time's a charm:
dark-dark-theme

@HebaruSan HebaruSan force-pushed the feature/consoleui-themes branch from b397f70 to 13f8b42 Compare January 20, 2021 19:37
@DasSkelett
Copy link
Member

Found an unrelated bug with the Console UI while testing this. Happens when leaving the path filed empty when adding a new game instance:

Unhandled Exception:
System.ArgumentException: The specified path is not of a legal form (empty).
at System.IO.Path.InsecureGetFullPath (System.String path) [0x00025] in <9969b53fa7824abc872802c31d2374b0>:0
at System.IO.Path.GetFullPath (System.String path) [0x00000] in <9969b53fa7824abc872802c31d2374b0>:0
at System.IO.DirectoryInfo..ctor (System.String path) [0x00006] in <9969b53fa7824abc872802c31d2374b0>:0
at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo..ctor(string)
at CKAN.ConsoleUI.GameInstanceScreen.pathValid () [0x00031] in <30624ca0a0a44ac58f64c7b4f4f2cf39>:0
at CKAN.ConsoleUI.GameInstanceAddScreen.Valid () [0x00009] in <30624ca0a0a44ac58f64c7b4f4f2cf39>:0
at CKAN.ConsoleUI.GameInstanceScreen.<.ctor>b__0_0 (System.Object sender, CKAN.ConsoleUI.Toolkit.ConsoleTheme theme) [0x00001] in <30624ca0a0a44ac58f64c7b4f4f2cf39>:0            

Fix should be as easy as this:

diff --git a/ConsoleUI/GameInstanceScreen.cs b/ConsoleUI/GameInstanceScreen.cs
index d9f55bc4..555a0b1e 100644
--- a/ConsoleUI/GameInstanceScreen.cs
+++ b/ConsoleUI/GameInstanceScreen.cs
@@ -94,6 +94,12 @@ protected bool nameValid()
         /// </summary>
         protected bool pathValid()
         {
+            if (string.IsNullOrEmpty(path.Value)) {
+                // Complain about empty path
+                RaiseError("Path cannot be empty!");
+                SetFocus(path);
+                return false;
+            }
             if (Platform.IsMac) {
                 // Handle default path dragged-and-dropped onto Mac's Terminal
                 path.Value = path.Value.Replace("Kerbal\\ Space\\ Program", "Kerbal Space Program");

Do you want to add it to this PR? Otherwise I can do a separate one.

Otherwise this looks good. I thought about adding a way to make the theme choice permanent so you don't have to add the argument yourself every time, and to help those launching the Console UI via the system menu entry from #3052. A new field in config.json?

@HebaruSan
Copy link
Member Author

Interestingly, that exception doesn't conform to the .NET documentation; ArgumentException is only supposed to be for invalid characters:

https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.-ctor?view=netframework-4.7.2#exceptions

I'm thinking this should catch all exceptions and treat them as failure...

@HebaruSan HebaruSan force-pushed the feature/consoleui-themes branch from 13f8b42 to 7531a03 Compare January 23, 2021 18:22
@HebaruSan
Copy link
Member Author

HebaruSan commented Jan 23, 2021

For a persistent setting, ConsoleUI currently has none of its own, and I'd prefer to keep it that way.
How about an environment variable?

EDIT: Now you should be able to affect the system menu entry by adding this to your environment (presumably ~/.bashrc, but maybe ~/.kde/env/ckan.sh):

export CKAN_CONSOLEUI_THEME=dark

@HebaruSan HebaruSan force-pushed the feature/consoleui-themes branch from 7531a03 to ee772f4 Compare January 23, 2021 19:07
@DasSkelett
Copy link
Member

Yeah, after writing the comment it came to me that we shouldn't put UI-specific settings into the core's config.json.

Environment variables are a good idea. I kinda hoped that CommandlineParser would support them already, but doesn't look like it. There's an open PR for it though: commandlineparser/commandline#698

@HebaruSan
Copy link
Member Author

I kinda hoped that CommandlineParser would support them already, but doesn't look like it.

Same, this made me miss Python's click.

@HebaruSan
Copy link
Member Author

Hold on, the "no such theme" message should print the valid options. Gimme a minute to add that...

Copy link
Member

@DasSkelett DasSkelett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm and looks very nice, even on Windows!

@HebaruSan HebaruSan force-pushed the feature/consoleui-themes branch from ee772f4 to b18d242 Compare January 23, 2021 20:50
@HebaruSan HebaruSan merged commit f8f0db2 into KSP-CKAN:master Jan 23, 2021
@HebaruSan HebaruSan deleted the feature/consoleui-themes branch January 23, 2021 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ConsoleUI Issues affecting the interactive console UI Enhancement New features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants